#include <iostream>
#include <memory>
#include <string>
#include <array>

using namespace std;

/*
\ brief:  抽象客户
\ author: 清晨与猫鱼
*/
class AbstractCustomer {
public:

    explicit AbstractCustomer() {  }

    explicit AbstractCustomer(string name)
        : name_(move(name)) {
    }

    virtual bool isNil() = 0;       // 是否为空
    virtual string getName() = 0;    
protected:
    string name_;
};


/*
\ brief:  真实的客户
\ author: 清晨与猫鱼
*/
class RealCustomer 
    : public AbstractCustomer {
public:
    explicit RealCustomer(string name) 
        : AbstractCustomer(move(name)) {
    }

    string getName() {
        return name_;
    }

    bool isNil() {
        return false;
    }
};


/*
\ brief:  不存在的客户
\ author: 清晨与猫鱼
*/
class NullCustomer 
    : public AbstractCustomer {
public:
    string getName() {
        return "Not Available in Customer Database";
    }

    bool isNil() {
        return true;
    }
};



/*
\ brief:  客户工厂
\ author: 清晨与猫鱼
*/
class CustomerFactory {
public:
    static array<string, 3> names;

    static AbstractCustomer* getCustomer(string name) {
        for (int i = 0; i < CustomerFactory::names.size(); ++i) {
            // 如果客户真是存在就返回真是客户对象
            if (CustomerFactory::names[i] == name) {
                return new RealCustomer(name);
            }
        }
        // 否则返回空对象
        return new NullCustomer;
    }
};

array<string, 3> CustomerFactory::names{"Rob", "Joe", "Julie"};     // 初始化
